<template>
  <div>
    <el-table :data="shopList" style="width: 100%">
      <el-table-column label="基本信息" width="600">
        <template #default="scope">
          <div>
            <img
              style="width: 88px; height: 88px"
              :src="
                'http://img2.haokoo.com/getImg.php?url=' + scope.row.coverImgUrl
              "
              alt=""
            />
            <span style="margin-left: 10px; display: inline-block">{{
              scope.row.name
            }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="价格" width="250">
        <template #default="scope">
          <!-- <i class="el-icon-time"></i> -->
          <span style="margin-left: 10px" v-if="scope.row.priceType == 1"
            >现价：￥{{ scope.row.price }}</span
          >
          <span style="margin-left: 10px" v-if="scope.row.priceType == 2"
            >￥{{ scope.row.price + '——' + '￥' + scope.row.price2 }}
          </span>
          <span style="margin-left: 10px" v-if="scope.row.priceType == 3"
            >{{
              '市场价：￥' +
              scope.row.price +
              '—' +
              '现价：￥' +
              scope.row.price2
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="链接" width="300">
        <template #default="scope">
          <!-- <i class="el-icon-time"></i> -->
          <span style="margin-left: 10px">{{ scope.row.url }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="300">
        <template #default="scope">
          <el-button
            type="info"
            size="mini"
            @click="handleEdit(scope.$index, scope.row)"
            >商品预览</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="primary"
            @click="handleModify(scope.$index, scope.row)"
            >修改价格</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <ShopDialog :goodsId="goodsId" ref="ShopDialog"></ShopDialog>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import ShopDialog from './ShopDialog.vue'
import { goShopList, goShopDelete } from '@/service/main/main'
import { ElMessageBox } from 'element-plus'
import { ElMessage } from 'element-plus'
export default defineComponent({
  components: { ShopDialog },
  async setup() {
    let dialogVisible = ref(false)
    let ShopDialog = ref()
    onMounted(() => {
      return ShopDialog
    })
    //获取商品列表
    const shopRes = await goShopList(0, 30, 2)
    let shopList = shopRes.goods

    const handleEdit = ($index: any, row: any) => {
      // console.log($index, row)
    }
    // 删除
    const open = (goodsId: number | string) => {
      ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          goShopDelete(goodsId)
          dialogVisible.value = false
          ElMessage({
            type: 'success',
            message: '删除成功!',
          })
        })
        .catch(() => {
          ElMessage({
            type: 'info',
            message: '已取消删除',
          })
        })
    }
    const handleDelete = ($index: any, row: any) => {
      // console.log(row.goodsId)
      open(row.goodsId)
    }
    let goodsId = ref()
    const handleModify = ($index: any, row: any) => {
      // console.log($index, row)
      ShopDialog.value.dialogFormVisible = true
      goodsId.value = row.goodsId
    }
    return {
      shopList,
      shopRes,
      dialogVisible,
      ShopDialog,
      goodsId,
      handleEdit,
      handleDelete,
      handleModify,
    }
  },
})
</script>

<style scoped></style>
